/***************************init***************/
function queryContract_contract(page){
	sys_loading();
	var parm = $('#queryContractForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('contract-query');
	sys_record_parm('contract',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#contractResultList').html(result);
		}
	});
}


function edit_contract(code) {
	var url = create_url('contract-edit');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm});
}

function aidExecuteContract_contract(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				queryContract_contract();
			} else {
				sys_msg('操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!', {
				    'buttons':  false,'modal': false, 'auto_close': 2000
				});
			}
		}
	});
}

function editContract_contract(code) {
	var parm = {'code':code};
	var url = create_url('contract-edit');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm});
}


function deleteContract_contract(code, name) {
	var url = create_url('contract-delete');
		$.Zebra_Dialog('要删除《' + name + '》合同吗?',{
		'type': 'question','title': '警告','buttons':[
           {caption:'确认',callback:function() {
        	   aidExecuteContract_contract(code, url);
    		}},
           {caption:'取消',callback:function(){}
    	}]
	});
}
/*******************************edit***********************/
function saveContract_contract() {
	console.log("mm");
	var parm = $('#editContractForm').serialize();
	var url = create_url('contract-save');
	console.log("11111");
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				sys_load_handle('contract');
			}else if(result == 'null_name') {
				sys_msg('名称不能为空');
			}else if(result == 'null_time') {
				sys_msg('到期时间不能为空');
			}else if(result == 'null_type') {
				sys_msg('还没上传合同');
			}else if(result == 'null_user') {
				sys_msg('人员不能为空');
			}else {
				sys_msg('操作失败');
			}
		}
	});
}

function addFilesUploadEvent_contract() {
	var url = create_url('contract-uploads');
	var btn = $('#uploadFilesBtn');
	new AjaxUpload(btn, {
		action:url,name:'files',multiple: true,responseType: 'json',
		onSubmit : function(file, ext) {
			if (ext && /^(zip|rar|txt|doc|docx|xls|xlsx|ppt|pptx|pdf|jpg|png|jpeg|gif|bmp|ZIP|RAR|TXT|DOC|DOCX|XLS|XLSX|PPT|PPTX|PDF|JPG|PNG|JPEG|GIF|BMP)$/.test(ext)){
			} else {
				sys_msg('文件类型错误', '只能上传类型为：zip、rar、txt、doc、docx、xls、xlsx、ppt、pptx、pdf、及图片文件!');
				return false;               
			}
			$('#uploads_span').html(sys_loading_img);
			this.disable();
		},
		onComplete: function(files, response){
			if ('error' == response.result)
				sys_msg('失败', '上传文件失败，请检查文件名是否正确!');
			else if ('file_type_error' == response.result)
				sys_msg('文件类型错误', '只能上传类型为：JGP、GIF、BMP、ICO、PNG的文件!');
			else {
				var template = $('#tempContractDiv').find('.rep');
				var annexList = $('#con');
				$.each(response.list, function(i) {
					$('#name').val(response.list[0].name);
					$('#size').val(response.list[0].size);
					$('#uuid').val(response.list[0].uuid);
					$('#ext').val(response.list[0].ext);
					$('#con').html('<img src="' + sys_context_path + 'images/flaticon/2.png"/>');
				});
				this.enable();
			}  
		},
		onUploadStart:function () {
		}
	});
}


function download_contract(path, code) {
	window.location.href = path + 'm/contract-download_' + code + ".html";
}


function showUc_contract(){
	$('#ucc').show();
	$('#bu').hide();
}

function showBu_contract(){
	$('#ucc').hide();
	$('#bu').show();
}